<template>
  <div class="component-list" @dragstart="handleDragStart">
    <div
      v-for="(item, index) in componentList"
      :key="index"
      class="list"
      draggable
      :data-index="index"
    >
      <span class="iconfont" :class="'icon-' + item.icon"></span>
      <span class="btn_name">{{ item.label }}</span>
    </div>
  </div>
</template>

<script>
import componentList from "@/custom-component/component-list";

export default {
  data() {
    return {
      componentList,
    };
  },
  methods: {
    handleDragStart(e) {
      e.dataTransfer.setData("index", e.target.dataset.index);
    },
  },
};
</script>

<style lang="scss" scoped>
.component-list {
  width: 200px;
  height: 55%;
  margin: 10px auto 0;
  display: grid;
  grid-gap: 10px 30px;
  grid-template-columns: repeat(auto-fill, 66px);
  grid-template-rows: repeat(auto-fill, 56px);

  .list {
    width: 66px;
    height: 56px;
    border: 1px solid #ddd;
    cursor: grab;
    text-align: center;
    color: #333;
    // background-color: #f3f3f3;
    border-radius: 8px;
    box-shadow: rgb(168 168 168 / 30%) 0px 2px 4px 0px;
    padding: 2px 5px;
    margin-left: 20px;

    &:active {
      cursor: grabbing;
    }

    .iconfont {
      display: block;
      font-size: 24px;
      margin-top: 3px;
      margin-bottom: 0px;
    }

    .icon-wenben,
    .icon-biaoge {
      font-size: 24px;
    }

    .icon-tupian {
      font-size: 24px;
    }
    .btn_name {
      font-size: 10px;
      line-height: 20px;
      color: rgb(31, 62, 104);
      width: 56px;
      padding: 0px 5px;
      word-break: keep-all;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
}
</style>
